package com.mriassl.stream.receiver;

import java.text.MessageFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.mriassl.stream.lib.rabbitmq.RabbitMQConst;


@Component
@RabbitListener(queues=RabbitMQConst.QUEUE_FOR_BETTING_REPLY_FAIL)
public class BettingFailReplyReceiver {
    private final Logger log = LoggerFactory.getLogger(BettingFailReplyReceiver.class);
    private Pattern pattern = Pattern.compile("^state:0,busno:(\\w+)$");

    @RabbitHandler
    public void receiveReply(String reply) {
        if (StringUtils.isBlank(reply)) return;
        Matcher matcher = pattern.matcher(reply);
        if (matcher.find()) {
            log.error(MessageFormat.format("投注账单保存失败，账单编号：{0}", matcher.group(1)));
            // 这里还可以做其他事情，比如发短信给运维人员，或开发人员
        }
    }

}
